package z_mxsTest.testArxmlSomeip.common;

import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class XmlParseComm {

    public static String getTextContent(Element parent, String tagName) {
        if (parent == null || tagName == null || tagName.isEmpty()) {
            return "";
        }

        NodeList children = parent.getChildNodes();

        for (int i = 0; i < children.getLength(); i++) {
            Node child = children.item(i);

            if (child.getNodeType() == Node.ELEMENT_NODE) {
                Element element = (Element) child;
                String fullTagName = element.getTagName();

                if (fullTagName.endsWith(":" + tagName) || fullTagName.equals(tagName)) {
                    String text = element.getTextContent().trim();
                    return text;
                }
            }
        }

        return "";
    }
}
